package com.example.ailiyuncloud.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ailiyuncloud.pojo.Result;
import com.example.ailiyuncloud.req.QueryCommodityOrderServiceReq;
import com.example.ailiyuncloud.service.CommodityOrderService;
import com.example.ailiyuncloud.vo.AddCommodityOrderVO;
import com.example.ailiyuncloud.vo.QueryCommodityOrderVO;
import com.example.ailiyuncloud.vo.QueryCommoditySkuVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: lqj
 * @Date: 2024/06/10/15:55
 * @Description:
 */
@RestController
@RequestMapping("/order")
public class CommodityOrderController {

    @Autowired
    private CommodityOrderService commodityOrderService;


    @PostMapping("/add")
    public Result<String> addCommoditySkuController(@RequestBody List<AddCommodityOrderVO> addCommodityOrderVOList) {
        try {
            commodityOrderService.addCommodityOrderService(addCommodityOrderVOList);
            return Result.OK();
        } catch (Exception e) {
            return Result.error("下单失败", e.getMessage().toString());
        }

    }


    @PostMapping("/query")
    public Result<List<QueryCommodityOrderServiceReq>> queryCommoditySkuController(@PageableDefault Page page,
                                                                             @RequestBody QueryCommodityOrderVO queryCommodityOrderVO) {
        return Result.OK(commodityOrderService.queryCommodityOrderService(page, queryCommodityOrderVO));
    }
}
